import {defineStore} from "pinia";
import {ref} from "vue";
import {reqUserCurrent} from "@/api/user.ts";

export const useLoginUserStore = defineStore('loginUserStore', ()=>{

  const loginUser = ref<any>({
    username: '未登录'
  })

  //远程获取登陆用户信息
  const fetchLoginUser = async () => {
    const res = await reqUserCurrent()
    if(res.data.code === 0){
      loginUser.value = res.data.data
    }
  }
  //单独设置登陆用户信息
  const setLoginUser = (user:any) => {
    loginUser.value = user
  }

  return {
    loginUser,
    fetchLoginUser,
    setLoginUser,

  }
})
